import base64
import json
import os
import re
import sys
import threading
from io import BytesIO

# from PIL import Image
# from cachetools import LRUCache, cached
# from ruamel.yaml import YAML
# 
# from api.db import FileType
# from api.constants import IMG_BASE64_PREFIX

PROJECT_BASE = os.getenv("RAG_PROJECT_BASE") or os.getenv("RAG_DEPLOY_BASE")
# RAG_BASE = os.getenv("RAG_BASE")

# LOCK_KEY_pdfplumber = "global_shared_lock_pdfplumber"
# if LOCK_KEY_pdfplumber not in sys.modules:
    # sys.modules[LOCK_KEY_pdfplumber] = threading.Lock()


def get_project_base_directory(*args):
    global PROJECT_BASE
    if PROJECT_BASE is None:
        PROJECT_BASE = os.path.abspath(
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                os.pardir,
                os.pardir,
            )
        )

    if args:
        return os.path.join(PROJECT_BASE, *args)
    return PROJECT_BASE
